const mysql = require('mysql');
const connection = mysql.createConnection({
    host:'127.0.0.1',
    // port:3306,
    user:'root',
    password:'root',
    database:'albx33'
})
// 建立暴露函数
module.exports = {
    // 封装一个验证用户名和密码是否一致的方法
     validateEmailAndPassword (email,password,callback){
         let sql = `SELECT *FROM users WHERE email= '${email}'AND \`password\` = '${password}'`;
         connection.query(sql,(err,result)=>{
            callback(err,result[0]);
         })
     },
     deleteUserById(id,callback){
         let sql = `UPDATE users SET isDelete = 1 WHERE id =${id}`;
         connection.query(sql,(err,result)=>{
             callback(err,result);
         })
     },
    //  封装一个获取所有用户的方法
    getAllUser(callback){
        let sql = `select * from users where isDelete = 0`;
        connection.query(sql,(err,result)=>{
            callback(err,result);
        })
    }
}